package org.oschina.api.user.active.service;

import java.util.List;
import org.oschina.Message;
import org.oschina.Module;
import org.oschina.ResultUtil;
import org.oschina.api.BaseService;
import org.oschina.api.user.active.dao.UserActiveTypeDAO;
import org.oschina.api.user.active.model.UserActiveType;
import org.oschina.api.user.active.vo.UserActiveTypeVo;
import org.oschina.bean.Result;
import org.oschina.security.annotation.Require;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserActiveTypeService extends BaseService {

	@Autowired
	private UserActiveTypeDAO userActiveTypeDAO;
	
	/**
	 * 返回
	 * @return
	 */
	@Require(authorization=Module.MODULE_46)
	public List<UserActiveTypeVo> findVo()
	{
		return _findVo();
	}
	
	/**
	 * 更新
	 * @param userActiveType
	 * @return
	 */
	@Require(authorization=Module.MODULE_46)
	public Result update(UserActiveType userActiveType)
	{
		if(_update(userActiveType)==0)
			return ResultUtil.getFailure(Message.ERROR_DATA_ERROR);
		
		return ResultUtil.getSuccess(userActiveType);
	}
	
	/**
	 * 返回
	 * @return
	 */
	private List<UserActiveTypeVo> _findVo()
	{
		return userActiveTypeDAO.findVo();
	}
	
	/**
	 * 根据ID返回
	 * @param id
	 * @return
	 */
	public UserActiveTypeVo _findVoById(int id)
	{
		return userActiveTypeDAO.findVoById(id);
	}
	
	/**
	 * 更新
	 * @param userActiveType
	 * @return
	 */
	private int _update(UserActiveType userActiveType)
	{
		return userActiveTypeDAO.update(userActiveType);
	}
}